package com.example.androidproject.novel.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.androidproject.R;
import com.example.androidproject.base.ListAsGridBaseAdapter;
import com.example.androidproject.novel.bean.NovelBean;

import java.util.ArrayList;

public class NovelAdapter extends ListAsGridBaseAdapter {
    private final Context mContext;
    private final ArrayList<NovelBean.DataBean> data;

    public NovelAdapter(Context context, ArrayList<NovelBean.DataBean> novelBodyDataList) {
        super(context);
        this.mContext = context;
        this.data = novelBodyDataList;
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getItemView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = View.inflate(mContext, R.layout.recomment_item, null);
            viewHolder = new ViewHolder();
            viewHolder.imageView = view.findViewById(R.id.iv_body);
            viewHolder.textView = view.findViewById(R.id.tv_body);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        Glide.with(mContext).load(data.get(i).getImage()).into(viewHolder.imageView);
        viewHolder.textView.setText(data.get(i).getTitle());
        return view;
    }

    class ViewHolder {
        ImageView imageView;
        TextView textView;
        LinearLayout linearLayout;
    }
}
